<!DOCTYPE html>
<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8"
	contentType="text/html;charset=utf-8"%>
<html>
<head>
<title>行政区划管理-编辑行政区划</title>
<jsp:include page="/common/head.jsp"></jsp:include>
<link
	href="<%=request.getContextPath()%>/static/plugin/zTree/css/zTreeStyle/zTreeStyle.css"
	rel="stylesheet">
<script
	src="<%=request.getContextPath()%>/static/plugin/zTree/js/jquery.ztree.all-3.5.min.js"></script>
</head>
<body class="iframe-page">

	<div class="page-title-wrapper">
		<div class="page-title">
			<div class="page-title-text">
				<span>行政区划管理</span> <span class="split"></span> <span>编辑行政区划</span>
			</div>
			<a id="goBack" class="btn-return distance-left" href="javascript:;"><i
				class="icon icon-arrow-left"></i>返回上级</a>
		</div>
		<div class="page-title-border"></div>
	</div>

	<form id="regionForm">
		<div class="form-wrapper">

			<div class="form-cont">
				<p class="form-cont-title">
					<span class="field-required">*</span>上级节点
				</p>
				<input type="hidden" id="id" name="id"  /> 
				<input type="hidden" id="pId" name="pId" /> 
				<input type="text" id="parentName" name="parentName" class="summer-input distance-right"
					readOnly /> <label class="label-secondary "></label>
			</div>

			<div class="form-cont">
				<p class="form-cont-title">
					<span class="field-required">*</span>名称
				</p>
				<input type="text" id="name" name="name"
					class="summer-input summer-validatebox distance-right"
					data-validatebox="validType:['required','maxLength[50]']" /> <label
					class="label-secondary "></label>
			</div>

			<div class="form-cont">
				<p class="form-cont-title">简称</p>
				<input type="text" id="sName" name="sName"
					class="summer-input summer-validatebox distance-right"
					data-validatebox="validType:['maxLength[20]']" /> <label
					class="label-secondary "></label>
			</div>
			<div class="form-cont">
				<p class="form-cont-title">
					<span class="field-required">*</span>类别
				</p>
				<input type="text" id="type" name="type"
					class="summer-input summer-validatebox distance-right"
					data-validatebox="validType:['required']" /> <label
					class="label-secondary "></label>
			</div>

			<div class="form-cont">
				<p class="form-cont-title">
					<span class="field-required">*</span>代码
				</p>
				<input type="text" id="code" name="code"
					class="summer-input distance-right" /> <label
					class="label-secondary "></label>
			</div>

			<div class="form-cont">
				<p class="form-cont-title">
					<span class="field-required">*</span>排序号
				</p>
				<input type="text" id="orderNo" name="orderNo"
					class="summer-input summer-validatebox distance-right"
					data-validatebox="validType:['required','betweenInteger[1,100000]']" />
				<label class="label-secondary "></label>
			</div>
		</div>
		<div class="form-btn-wrapper">
		    <a class="btn btn-normal btn-ok distance-right" id="saveBtn">保存</a>
		</div>
	</form>
	<div class="callout callout-ok" style="margin-top: 20px;">
		<h4>操作说明</h4>
		<p>1、当前行政区划是省级别时请填写简称</p>
	</div>

	<script>
         
         var REGION_URL = {
             EDIT: basePath + '/sys/region/edit',
             CHECKEXIST: basePath + "/sys/region/isExist",
             INIT_STAT: basePath + '/sys/region/initStat'
         };
         var data = ${r};
        $(function() {
        	 $("#regionForm").form({
                 buttons : ['#saveBtn'],
                 ajax: {
                     url: REGION_URL.EDIT,
                 },
                 onSubmitSuccess: function(data){
                   $.stip({
                       type:'ok',//显示类型 有info、 ok、 danger
                       text: '保存成功！',
                       onBeforeHide: function () {
                    	   var pId = document.getElementById('pId').value;
                           parent.refreshPage(pId);
                      }
                   });
                   
                   
                 }
             });
        	 
            $("#type").combobox({
            	async: false,
                valueField: 'code',
                textField:  'name',
                menuHeight: 130,
                url : COMMON_URL.getCode + "?type=T_DM_REGION_TYPE",
                onLoadSuccess : function(){
                	$("#regionForm").form('loadDataEdit',{
                        data: data
                    });
                }
            });
            $('#saveBtn').click(save);
            // 返回按钮事件
            $('#goBack').on('click',goBack);
            //校验代码code是否可用   
            validateExist('#code','code', REGION_URL.CHECKEXIST, ['required','maxLength[12]','regexp'], "代码可用");
        });
        
        function save() {
             $("#regionForm").form("submit");
        }
        // 校验代码code是否可用
        function validateExist(id, name, url, validType, message) {
            $(id).validatebox({
                rules: {
                    regexp: {
                        validator: function (value,param) {
                            var result = false,
                                params = {}, 
                                key = name;
                                params[key] = value;
                                params['id'] = $("#id").val();
                            $.ajax({
                                type: 'post',
                                url: url,
                                data: params,
                                dataType: 'json',
                                async: false,
                                success: function (data) {
                                    result = !(data.result == 'exist');
                                }
                            });
                            return result;
                        },
                        message: message,
                    }
                },
                validType: validType
            });
        }
        // 返回
        function goBack() {
            window.location.href=REGION_URL.INIT_STAT;
        }
     </script>
</body>
</html>
